<?php

/**
 * @author chenshubo
 * 查询商品SKU清单
 */
namespace App\Service\OrderService\OrderInterfaceService;

use App\Service\Code\Normal;
use App\Service\BaseService;
use App\Model\PssModel\MerchantGoodsList;

class QueryGoodsSkuLists extends BaseService
{    
    //SKU数量限制
    protected $query_sku_count = 50 ;
    
    /**
     * 查询订单物流单号
     */
    public function index( $param = [] ) 
    {
        $requestData = $param['requestData'];
        if( empty($requestData['SkuCodeList']) ) {
            return Normal::returnCode(Normal::FAIL,"缺少SkuCodeList参数");
        }
        
        if( !is_array($requestData['SkuCodeList']) ) {
            return Normal::returnCode(Normal::FAIL,"SkuCodeList必须为数组");
        }
        
        if( count($requestData['SkuCodeList']) > $this->query_sku_count ) {
            return Normal::returnCode(Normal::FAIL,"查询商品数组不能大于{$this->query_sku_count}个");
        }
        
        $SkuCodeList = array_unique(array_filter($requestData['SkuCodeList']));
        //获取授权商品
        $authGoodsLists = MerchantGoodsList::instance()
        ->where('bid',$param['binfo']['bid'])
        ->whereIn('skucode',$SkuCodeList)
        ->get()
        ->toArray();
        if( empty($authGoodsLists) ) {
            return Normal::returnCode(Normal::FAIL,"未查询到可用的商品sku数据");
        }
        
        //获取五层结构数据
        $goodsLists = MerchantGoodsList::instance()->getPushGoodsList($authGoodsLists);
        return Normal::returnCode(Normal::SUC,"获取成功",[
            'goodsLists' => $goodsLists
        ]);
    }
}